package com.example.OJ.controller;

import com.example.OJ.dao.Message;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {
    private List<Message> messages = new ArrayList<>();

    @RequestMapping("/publish")
    public boolean publishMessage(Message message){
        //参数校验
        if(!StringUtils.hasLength(message.getFrom())
                || !StringUtils.hasLength(message.getTo())
                || !StringUtils.hasLength(message.getMessage())){
            return false;
        }

        //添加留言
        messages.add(message);
        return true;
    }

    @RequestMapping("/getMessageInfo")
    public List<Message> getMessageInfo(){
        return messages;
    }
}
